import Cookies from 'js-cookie'

const state = {
  clusterId: Cookies.get('clusterId'),
  clusterName: Cookies.get('clusterName'),
  clusterCode: Cookies.get('clusterCode')
}

const mutations = {
  SET_CLUSTER_ID: (state, clusterId) => {
    state.clusterId = clusterId
    Cookies.set('clusterId', clusterId)
  },
  SET_CLUSTER_NAME: (state, clusterName) => {
    state.clusterName = clusterName
    Cookies.set('clusterName', clusterName)
  },
  SET_CLUSTER_CODE: (state, clusterCode) => {
    state.clusterCode = clusterCode
    Cookies.set('clusterCode', clusterCode)
  }
}
const actions = {
  setClusterId({ commit }, data) {
    commit('SET_CLUSTER_ID', data)
  },
  setClusterName({ commit }, data) {
    commit('SET_CLUSTER_NAME', data)
  },
  setClusterCode({ commit }, data) {
    commit('SET_CLUSTER_CODE', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
